<template>
  <div class="login-container">
    <!-- 账号输入框 -->
    <div class="input-group">
      <label for="username">账号</label>
      <div class="input-wrapper">
        <input
          id="username"
          v-model="username"
          type="text"
          placeholder="请输入手机号/邮箱"
          class="input-field"
        />
        <button 
          v-show="username"
          class="clear-btn"
          @click="clearUsername"
          @mousedown.prevent
        >
          <svg width="16" height="16" viewBox="0 0 24 24">
            <path fill="#999" d="M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z"/>
          </svg>
        </button>
      </div>
    </div>

    <!-- 密码输入框 -->
    <div class="input-group">
      <label for="password">密码</label>
      <div class="input-wrapper">
        <input
          id="password"
          v-model="password"
          :type="showPassword ? 'text' : 'password'"
          placeholder="请输入密码"
          class="input-field"
        />
        <button 
          class="eye-btn"
          @click="togglePassword"
          @mousedown.prevent
        >
          <!-- 简化版小眼睛图标 - 无切换动画 -->
          <svg width="20" height="20" viewBox="0 0 24 24">
            <path v-if="showPassword" fill="#999" d="M12 6a9.77 9.77 0 0 1 8.82 5.5A9.77 9.77 0 0 1 12 17a9.77 9.77 0 0 1-8.82-5.5A9.77 9.77 0 0 1 12 6m0-2C7 4 2.73 7.11 1 11.5 2.73 15.89 7 19 12 19s9.27-3.11 11-7.5C21.27 7.11 17 4 12 4zm0 5a2.5 2.5 0 0 1 0 5 2.5 2.5 0 0 1 0-5m0-2c-2.48 0-4.5 2.02-4.5 4.5S9.52 16 12 16s4.5-2.02 4.5-4.5S14.48 7 12 7z"/>
            <path v-else fill="#999" d="M12 7c2.76 0 5 2.24 5 5 0 .65-.13 1.26-.36 1.83l2.92 2.92c1.51-1.26 2.7-2.89 3.43-4.75-1.73-4.39-6-7.5-11-7.5-1.4 0-2.74.25-3.98.7l2.16 2.16C10.74 7.13 11.35 7 12 7zM2 4.27l2.28 2.28.46.46A11.804 11.804 0 0 0 1 12c1.73 4.39 6 7.5 11 7.5 1.55 0 3.03-.3 4.38-.84l.42.42L19.73 22 21 20.73 3.27 3 2 4.27zM7.53 9.8l1.55 1.55c-.05.21-.08.43-.08.65 0 1.66 1.34 3 3 3 .22 0 .44-.03.65-.08l1.55 1.55c-.67.33-1.41.53-2.2.53-2.76 0-5-2.24-5-5 0-.79.2-1.53.53-2.2zm4.31-.78l3.15 3.15.02-.16c0-1.66-1.34-3-3-3l-.17.01z"/>
          </svg>
        </button>
      </div>
    </div>

    <button class="login-btn" @click="handleLogin">登录</button>
  </div>
</template>

<script lang="ts">
import { defineComponent, ref } from 'vue';

export default defineComponent({
  name: 'LoginPage',
  setup() {
    const username = ref('');
    const password = ref('');
    const showPassword = ref(false);

    const clearUsername = () => {
      username.value = '';
    };

    const togglePassword = () => {
      showPassword.value = !showPassword.value;
    };

    const handleLogin = () => {
      console.log('登录信息:', { username: username.value, password: password.value });
      // 实际登录逻辑
    };

    return {
      username,
      password,
      showPassword,
      clearUsername,
      togglePassword,
      handleLogin
    };
  }
});
</script>

<style scoped>
.login-container {
  max-width: 90%;
  margin: 2rem auto;
  padding: 2rem;
}

.input-group {
  margin-bottom: 1.8rem;
}

label {
  display: block;
  margin-bottom: 0.5rem;
  font-size: 0.9rem;
  color: #666;
}

.input-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

.input-field {
  flex: 1;
  padding: 14px 16px;
  padding-right: 42px;
  border: 1px solid #ddd;
  border-radius: 8px;
  font-size: 1rem;
  background: #f9f9f9;
}

.input-field:focus {
  border-color: #4a8cff;
  background: #fff;
  outline: none;
}

.clear-btn, .eye-btn {
  position: absolute;
  right: 12px;
  background: none;
  border: none;
  padding: 6px;
  cursor: pointer;
  opacity: 0.7;
}

.clear-btn:hover, .eye-btn:hover {
  opacity: 1;
}

.login-btn {
  width: 100%;
  padding: 14px;
  background: #4a8cff;
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 1rem;
  cursor: pointer;
  margin-top: 1rem;
}

/* 移除所有变换动画 */
.clear-btn, 
.eye-btn, 
.login-btn {
  transition: none;
  transform: none;
}

/* 移动端优化 */
@media (max-width: 480px) {
  .login-container {
    padding: 1.5rem;
  }
  
  .input-field {
    padding: 12px 14px;
  }
}
</style>